# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/8 22:40
# @Author   : Robot-Zsj
"""
description:

input
1 4 3 4 5
r y b b r
output
3
"""
nums = input().split()
colors = input().split()


class Card:
    def __init__(self, num, color):
        self.num = num
        self.color = color


def dfs(cards, used, last, count, ans):
    ans[0] = max(ans[0], count)

    for i in range(len(cards)):
        if used[i]:
            continue

        cur = cards[i]
        if last and last.num != cur.num and last.color != cur.color:
            continue

        used[i] = True
        dfs(cards, used, cur, count + 1, ans)
        used[i] = False


def getResult():
    n = len(nums)
    cards = [Card(nums[i], colors[i]) for i in range(n)]

    ans = [0]
    used = [False] * n

    dfs(cards, used, None, 0, ans)

    return ans[0]


print(getResult())
